package com.briup.pts.web.controller;

import com.briup.pts.entity.ManagerFenceHouse;
import com.briup.pts.entity.extend.ManagerFenceHouseExt;
import com.briup.pts.result.Result;
import com.briup.pts.service.FenceHouseService;
import com.briup.pts.service.HurdlesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "栏舍管理模块")
@RestController
@RequestMapping("/fenceHouse")
public class FenceHouseController {
    @Autowired
    private FenceHouseService fenceHouseService;
    @Autowired
    private HurdlesService hurdlesService;

    @ApiOperation("分页多条件查询栏舍信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码",
                    defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",
                    defaultValue = "10", required = true),
            @ApiImplicitParam(name = "fhName",value = "栏舍名称")
    })
    @GetMapping
    public Result getAll(@RequestParam Integer pageNum,
                         @RequestParam Integer pageSize,
                         String fhName){
        PageInfo<ManagerFenceHouse> page = fenceHouseService.findByPage(pageNum, pageSize, fhName);
        return Result.success(page);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerFenceHouse managerFenceHouse){
        fenceHouseService.saveOrUpdate(managerFenceHouse);
        return Result.success();
    }

    @DeleteMapping("/{fhId}")
    public Result removeByFhId(@PathVariable String fhId){
        fenceHouseService.removeById(fhId);
        return Result.success();
    }

    @DeleteMapping("/deleteByIdAll")
    public Result removeBatch(@RequestBody List<String> ids){
        fenceHouseService.removeBatch(ids);
        return Result.success();
    }

    @GetMapping("/{fhId}")
    public Result<ManagerFenceHouseExt> findById(@PathVariable String fhId){
        return Result.success(fenceHouseService.findById(fhId));
    }

    @GetMapping("/queryAll")
    public Result queryAll(){
        return Result.success(hurdlesService.findAll());
    }

}